FROM php:7.2.34-fpm as php72-fpm
# 切换源
# htts兼容命令
#RUN apt-get install -y apt install apt-transport-https ca-certificates
RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak \
    && echo "deb http://mirrors.ustc.edu.cn/debian/ buster main" >>/etc/apt/sources.list \
    && echo "# deb-src http://mirrors.ustc.edu.cn/debian/ buster main" >>/etc/apt/sources.list \
    && echo "deb http://mirrors.ustc.edu.cn/debian-security buster/updates main" >>/etc/apt/sources.list \
    && echo "# deb-src http://mirrors.ustc.edu.cn/debian-security buster/updates main" >>/etc/apt/sources.list \
    && echo "deb http://mirrors.ustc.edu.cn/debian/ buster-updates main" >>/etc/apt/sources.list \
    && echo "# deb-src http://mirrors.ustc.edu.cn/debian/ buster-updates main" >>/etc/apt/sources.list\
    # MYSQL新增
    && echo "deb https://mirrors.ustc.edu.cn/debian unstable main contrib non-free" >>/etc/apt/sources.list \
    && echo "deb https://mirrors.ustc.edu.cn/debian experimental main contrib non-free" >>/etc/apt/sources.list

## 安装扩展
RUN apt-get update
RUN apt-get install -y libfreetype6-dev
RUN apt-get install -y libjpeg62-turbo-dev
RUN apt-get install -y libmcrypt-dev
RUN apt-get install -y libpng-dev
RUN apt-get install -y build-essential
RUN apt-get install -y libmagickcore-dev
RUN apt-get install -y libmagickwand-dev
RUN apt-get install -y imagemagick
# M1 TODO
# RUN apt-get install -y libmpx2
# M1 TODO
RUN apt-get install -y mysql-client

RUN docker-php-source extract
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install -j$(nproc) \
        iconv pdo_mysql  mysqli bcmath calendar exif gettext sockets \
        dba pcntl shmop sysvmsg sysvsem sysvshm gd zip
# M1 TODO
# RUN apt-get install -y gcc-8-base libgcc-8-dev
# M1 TODO
RUN apt-get update && apt-get install -y libc6-dev
# imagick、xlswriter、swoole环境
RUN apt-get install -y libmagickwand-dev g++ libssl-dev build-essential zlibc  libidn11-dev libidn11
# kakfa扩展安装
RUN apt-get install -y librdkafka-dev
# 安装自定义插件 pecl: https://pecl.php.net/package-search.php
RUN pecl install mcrypt \
    && pecl install imagick \
    && pecl install redis-3.1.6 \
    && pecl install xlswriter-1.3.6 \
    && pecl install xdebug-2.9.8 \
    && pecl install xhprof-2.2.2 \
    && pecl install swoole-4.5.9 \
    && pecl install rdkafka-6.0.1 \
    && docker-php-ext-enable mcrypt imagick redis xlswriter xhprof swoole rdkafka xdebug
# 安装易用扩展
RUN apt-get update && apt-get install -y vim sudo less git zip unzip lrzsz net-tools graphviz wget iputils-ping supervisor openssh-server
# 安装PHP composer
RUN php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');" \
    && php composer-setup.php \
    && php -r "unlink('composer-setup.php');" \
    && sudo mv composer.phar /usr/local/bin/composer \
    && composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ \
    && composer global require laravel/installer \
    && echo "alias laravel='~/.composer/vendor/bin/laravel'" >>~/.bashrc
    #laravel 安装器 #composer global update #laravel -V #laravel new blog
# 旧版本composer
#COPY ./composer.phar /usr/local/bin/composer
#RUN composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

##### composer create-project --prefer-dist laravel/laravel jd 5.8.*
##### composer create-project --prefer-dist laravel/lumen luaa 5.8.*
# 自定义服务
RUN echo "export LS_OPTIONS='--color=auto'" >>~/.bashrc
RUN echo "eval "`dircolors`"" >>~/.bashrc
RUN echo "alias ll='ls \$LS_OPTIONS -l'" >>~/.bashrc
RUN ln -sfn /var/www /root/www \
    && ln -sfn /var/log /root/log

COPY ./ssh/authorized_keys /root/.ssh/authorized_keys
COPY ./ssh/sshd_config /etc/ssh/sshd_config
COPY ./supervisor/supervisord.conf /etc/supervisor/supervisord.conf
#COPY supervisor/ini/sshd.ini /usr/supervisord/sshd.ini
RUN mkdir /run/sshd
CMD ["/usr/bin/supervisord"]